<?php
class TgiachidoansController extends AppController {

	var $name = 'Tgiachidoans';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Tgiachidoan->recursive = 0;
		$this->set('tgiachidoans', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Tgiachidoan.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('tgiachidoan', $this->Tgiachidoan->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Tgiachidoan->create();
			if ($this->Tgiachidoan->save($this->data)) {
				$this->Session->setFlash(__('The Tgiachidoan has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Tgiachidoan could not be saved. Please, try again.', true));
			}
		}
		$chidoansvs = $this->Tgiachidoan->Chidoansv->find('list');
		$sinhviens = $this->Tgiachidoan->Sinhvien->find('list');
		$this->set(compact('chidoansvs', 'sinhviens'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Tgiachidoan', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Tgiachidoan->save($this->data)) {
				$this->Session->setFlash(__('The Tgiachidoan has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Tgiachidoan could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Tgiachidoan->read(null, $id);
		}
		$chidoansvs = $this->Tgiachidoan->Chidoansv->find('list');
		$sinhviens = $this->Tgiachidoan->Sinhvien->find('list');
		$this->set(compact('chidoansvs','sinhviens'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Tgiachidoan', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Tgiachidoan->del($id)) {
			$this->Session->setFlash(__('Tgiachidoan deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>